package com.akk.module.yb.model;

import com.akk.PayConstants;
import com.akk.module.yb.utils.Digest;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.StringPart;

import java.util.ArrayList;
import java.util.List;

/**
 * 收款请求
 */
public class ReceiveRequest {
    private String mainCustomerNumber; // 代理商商户编号
    private String customerNumber; //商户编号
    private String requestId; //收款订单号
    private String source; //支付方式
    private String amount; //订单金额
    private String mcc; //商品分类
    private String callBackUrl; //收款成功回调地址
    private String webCallBackUrl; //页面回调地址
    private String mobileNumber; //手机号
    private String smgCallBackUrl; //短信发送成功回调地址
    private String payerBankAccountNo; //支付卡号
    private String productVersion; // 产品版本

    private String hmac; //签名信息

    public String getMainCustomerNumber() {
        return mainCustomerNumber;
    }

    public void setMainCustomerNumber(String mainCustomerNumber) {
        this.mainCustomerNumber = mainCustomerNumber;
    }

    public String getCustomerNumber() {
        return customerNumber;
    }

    public void setCustomerNumber(String customerNumber) {
        this.customerNumber = customerNumber;
    }

    public String getRequestId() {
        return requestId;
    }

    public void setRequestId(String requestId) {
        this.requestId = requestId;
    }

    public String getSource() {
        return source;
    }

    public void setSource(String source) {
        this.source = source;
    }

    public String getAmount() {
        return amount;
    }

    public void setAmount(String amount) {
        this.amount = amount;
    }

    public String getMcc() {
        return mcc;
    }

    public void setMcc(String mcc) {
        this.mcc = mcc;
    }

    public String getCallBackUrl() {
        return callBackUrl;
    }

    public void setCallBackUrl(String callBackUrl) {
        this.callBackUrl = callBackUrl;
    }

    public String getWebCallBackUrl() {
        return webCallBackUrl;
    }

    public void setWebCallBackUrl(String webCallBackUrl) {
        this.webCallBackUrl = webCallBackUrl;
    }

    public String getMobileNumber() {
        return mobileNumber;
    }

    public void setMobileNumber(String mobileNumber) {
        this.mobileNumber = mobileNumber;
    }

    public String getSmgCallBackUrl() {
        return smgCallBackUrl;
    }

    public void setSmgCallBackUrl(String smgCallBackUrl) {
        this.smgCallBackUrl = smgCallBackUrl;
    }

    public String getPayerBankAccountNo() {
        return payerBankAccountNo;
    }

    public void setPayerBankAccountNo(String payerBankAccountNo) {
        this.payerBankAccountNo = payerBankAccountNo;
    }

    public String getHmac() {
        return hmac;
    }

    public void setHmac(String hmac) {
        this.hmac = hmac;
    }

    public static String signature(ReceiveRequest request) {
        StringBuffer sb = new StringBuffer();
        sb.append(request.getSource() == null?"":request.getSource());
        sb.append(request.getMainCustomerNumber() == null?"":request.getMainCustomerNumber());
        sb.append(request.getCustomerNumber() == null? "":request.getCustomerNumber());
        sb.append(request.getAmount() == null?"":request.getAmount());
        sb.append(request.getMcc() == null?"":request.getMcc());
        sb.append(request.getRequestId() == null?"":request.getRequestId());
        sb.append(request.getMobileNumber() == null?"":request.getMobileNumber());
        sb.append(request.getCallBackUrl()== null?"":request.getCallBackUrl());
        sb.append(request.getWebCallBackUrl() == null?"":request.getWebCallBackUrl());
        sb.append(request.getSmgCallBackUrl()== null?"":request.getSmgCallBackUrl());
        sb.append(request.getPayerBankAccountNo() == null?"":request.getPayerBankAccountNo());
        return Digest.hmacSign(sb.toString(), PayConstants.YB_PARAMS_HMAC_KEY);
    }

    public static Part[] builderPart(ReceiveRequest request) {
        List<Part> parts = new ArrayList<Part>();
        parts.add(new StringPart("productVersion",request.getProductVersion() == null ? "":request.getProductVersion(),"UTF-8"));
        parts.add(new StringPart("mainCustomerNumber",request.getMainCustomerNumber()==null?"":request.getMainCustomerNumber(),"UTF-8"));
        parts.add(new StringPart("amount",request.getAmount()==null?"":request.getAmount(),"UTF-8"));
        parts.add(new StringPart("callBackUrl",request.getCallBackUrl()==null?"":request.getCallBackUrl(),"UTF-8"));
        parts.add(new StringPart("customerNumber",request.getCustomerNumber()==null?"":request.getCustomerNumber(),"UTF-8"));
        parts.add(new StringPart("hmac",request.getHmac() == null ?"":request.getHmac(),"UTF-8"));
        parts.add(new StringPart("mcc",request.getMcc()==null?"":request.getMcc(),"UTF-8"));
        parts.add(new StringPart("mobileNumber",request.getMobileNumber()==null?"":request.getMobileNumber(),"UTF-8"));
        parts.add(new StringPart("requestId",request.getRequestId()==null?"":request.getRequestId(),"UTF-8"));
        parts.add(new StringPart("smgCallBackUrl",request.getSmgCallBackUrl()==null?"":request.getSmgCallBackUrl(),"UTF-8"));
        parts.add(new StringPart("source",request.getSource()==null?"":request.getSource(),"UTF-8"));
        parts.add(new StringPart("webCallBackUrl",request.getWebCallBackUrl()==null?"":request.getWebCallBackUrl(),"UTF-8"));
        parts.add(new StringPart("payerBankAccountNo",request.getPayerBankAccountNo()==null?"":request.getPayerBankAccountNo(),"UTF-8"));
        return parts.toArray(new Part[parts.size()]);
    }

    public String getProductVersion() {
        return productVersion;
    }

    public void setProductVersion(String productVersion) {
        this.productVersion = productVersion;
    }
}
